#!/usr/bin/env python
from simpledcpp.gui.base import gtk_lock_required

class ConnectDialog:
	@gtk_lock_required
	def __init__(self, parent):
		self.parent = parent
		self._widget = self.parent.wtree.get_widget("ConnectDialog")
		self._entry = self.parent.wtree.get_widget("ConnectEntry")
		self.parent.wtree.get_widget("ConnectOk").connect("clicked", self.on_connect)
		self.parent.wtree.get_widget("ConnectCancel").connect("clicked", self.on_cancel)
		self._entry.connect("key-press-event", self._onkey)
		self._widget.connect("close", self.hide)

	@gtk_lock_required
	def show(self, *args, **kwargs):
		self._widget.show()

#	@gtk_lock_required
	def _onkey(self, Entry = None, Event = None, Data = None):
		if Event.keyval == 65293:
			self.on_connect(None, None)

	def on_cancel(self, Event = None, Data = None):
		self.hide()

	def on_connect(self, Event = None, Data = None):
		if len(self._entry.get_text()) > 0:
			self.hide()
			self.parent._connectTo(self._entry.get_text().strip())	

	@gtk_lock_required
	def hide(self, *args, **kwargs):
		self._widget.hide()
